#!/bin/bash

# Tiny QA Docker 构建脚本

echo "========================================"
echo "Tiny QA - Docker 构建脚本"
echo "========================================"

# 检查Docker是否安装
if ! command -v docker &> /dev/null; then
    echo "❌ 错误: Docker未安装"
    echo "请访问 https://docs.docker.com/get-docker/ 安装Docker"
    exit 1
fi

# 检查Docker Compose是否安装
if ! command -v docker-compose &> /dev/null; then
    echo "❌ 错误: Docker Compose未安装"
    echo "请安装Docker Compose"
    exit 1
fi

echo "✅ Docker环境检查通过"

# 设置镜像名称和标签
IMAGE_NAME="tiny-qa"
TAG="latest"
FULL_IMAGE_NAME="${IMAGE_NAME}:${TAG}"

echo ""
echo "🔨 开始构建Docker镜像..."
echo "镜像名称: ${FULL_IMAGE_NAME}"

# 构建镜像
docker build -t ${FULL_IMAGE_NAME} .

if [ $? -eq 0 ]; then
    echo "✅ Docker镜像构建成功!"
    
    echo ""
    echo "📊 镜像信息:"
    docker images ${FULL_IMAGE_NAME}
    
    echo ""
    echo "🚀 启动服务:"
    echo "docker-compose up -d"
    
    echo ""
    echo "📋 其他常用命令:"
    echo "查看日志: docker-compose logs -f"
    echo "停止服务: docker-compose down"
    echo "重启服务: docker-compose restart"
    echo "进入容器: docker exec -it tiny-qa bash"
    
else
    echo "❌ Docker镜像构建失败"
    exit 1
fi 